<?php

namespace app\common\model\goods;

use think\Model;
use think\Db;

class Cate extends Model
{

    

    

    // 表名
    protected $name = 'goods_cate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    /**
     * 读取分类类型
     * @return array
     */
    public static function getTypeList()
    {
        $typeList = config('site.categorytype');
        foreach ($typeList as $k => &$v) {
            $v = __($v);
        }
        return $typeList;
    }
    
    public function catenumber($cid,$number=[]){

        $cinfo = Db::name('goods_cate')->where(array('id'=>$cid))->find();
        $count = Db::name('goods_cate')->where(array('pid'=>$cinfo['pid'],'id'=>array('<',$cinfo['id'])))->count();

        $number[] = getnumbers($count);

        if($cinfo['pid'] != 0){
            return $this->catenumber($cinfo['pid'],$number);
        }

        $number = array_reverse($number);
        return implode('',$number);
    }






}
